<template>
	<view>
		<view class="top_nav_box">
			<navigation-custom :config="config" @customConduct="customConduct" />
		</view>
		<view class="page_item_bj"></view>
		<view class="page_content_box">
			<view :style="{height:statusHeight+'px'}"></view>
			<view class="auth_step_img">
				<image src="../../static/images/appeal_icon1.png" mode=""></image>
			</view>
			<view class="auth_step_info_box">
				<view class="auth_step_info_title"><text>申诉原因</text></view>
				<view class="phone_login_input_box">
					<view class="phone_login_input_name">申诉原因 <text>*</text></view>
					<view class="pick_box">
						 <picker @change="bindPickerChange" :value="index" :range="reason_array">
						    <view class="pick_input pick_input1"  v-if="reason_index== -1">请选择申诉原因</view>
							<view class="pick_input" v-if="reason_index!= -1">{{reason_array[reason_index]}}</view>
						 </picker>
						 <view class="pick_img">
							<image src="https://www.cccshansong.com/chong_weapp/auth_bottom.png" mode=""></image>
						 </view>
					</view>
				</view>
				<view class="ask_text_box">
					<view class="ask_textarea">
						<textarea v-model="ask_desc" placeholder="请填写问题描述以便我们提供更好的帮助"  :show-confirm-bar="false" @input="conInput" @blur="handleBlur" maxlength="300" ></textarea>
					</view>
					<view class="ask_text_num">{{ask_desc_num}}/300</view>
				</view>
				<view class="ask_img_box">
					<view class="ask_title">提供问题截图（{{ceshiData.length}}/3）</view>
					<view class="img_list">
						<htz-image-upload  :max="3"  v-model="ceshiData" @imgDelete='imgDelete' @uploadSuccess="ceshiUploadSuccess" :action="action_url" ></htz-image-upload>
					</view>
				</view>
			</view>
		</view>
		<view class="record_fix_box">
			<view class="record_fix_btn" hover-class="hover_class" @click="handleSubmit()">提交</view>
		</view>
	</view>
</template>

<script>
	import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
	import navigationCustom from "@/components/struggler-navigationCustom/navigation-custom.vue"
	export default {
		components: {
			navigationCustom,
			htzImageUpload,
		},
		data() {
			return {
				btn_status:true,
				order_id:0,
				reason_array: ['商家原因', '天气原因', '个人原因', ],
				reason_index: -1,
				ask_desc:'',
				ask_desc_num:0,
				action_url:'',
				image_arr:[],
				ceshiData:[],
				statusHeight:0,
				config: {
					title: "我要申诉", //title
					bgcolor: "transparent", //背景颜色
					fontcolor: "#fff", //文字颜色，默认白色
					type: 4, //type 1，3胶囊 2，4无胶囊模式
					transparent: false, //是否背景透明 默认白色
					linear: false, //是为开启下滑渐变
					share: false, //是否将主页按钮显示为分享按钮
					menuIcon: "../../static/icon/back2.png", //当type为3或者4的时候左边的icon文件位置，注意位置与当前页面不一样
					// menuText:"返回", //当type为3或4的时候icon右边的文字
				},
			};
		},
		onLoad(e) {
			var a = this
			a.statusHeight = uni.getSystemInfoSync().statusBarHeight  + 48
			a.action_url = a.globalurl + 'common/image_upload'
			a.order_id = e.order_id
		},
		onPageScroll(res) {
			var a = this
			if (0 < res.scrollTop <= 60) {
				a.config.bgcolor = 'rgba(65, 138, 255,0)'
			}

		},
		methods: {
			 bindPickerChange: function(e) {
			    this.reason_index = e.detail.value
			},
			customConduct() {
				uni.navigateBack({
					delta: 1
				})
			},
			handleSubmit(){
				var a = this
				if(a.reason_index == -1){
					uni.showToast({
						title:'请选择申诉原因',
						icon:'none'
					})
				}else if(a.ask_desc==''){
					uni.showToast({
						title:'请详细描述问题',
						icon:'none'
					})
				}else if(a.ceshiData.length==0){
					uni.showToast({
						title:'请上传图片',
						icon:'none'
					})
				}else{
					if(a.btn_status){
						a.btn_status = false
						uni.showLoading({
							title:'加载中'
						})
						var temp_arr = ''
						if(a.ceshiData.length>0){
							temp_arr = JSON.stringify(a.ceshiData)
						}else{
							temp_arr = ''
						}
						a.globalajax('wallet/refund',{
							order_id:a.order_id,
							price:'5',
							recource:a.reason_array[a.reason_index],
							remark:a.ask_desc,
							image:temp_arr
							},'POST',function(res) {
								console.log(res);
								uni.hideLoading()
								uni.stopPullDownRefresh()
								setTimeout(()=>{
									a.btn_status = true
								},1500)
								if(res.data.code==200){
									uni.redirectTo({
										url:'/pages/user/appealSucc'
									})
								}else{
									a.$showModal({
										title:'友情提示',
										content:res.data.msg,
										showCancel:false,
										confirmText:'我知道了',
										success: (res) => {
										}
									});
								}
							}
						);
					}
				}
			},
			imgDelete(e){
				this.image_arr.splice(e.index, 1)
			},
			ceshiUploadSuccess(res) { //上传成功
				var _res = JSON.parse(res.data);
				console.log(_res)
				this.image_arr.push(_res.data.complete_url);
				this.ceshiData.push(_res.data.complete_url);
			},
			conInput(e){
				var temp_value = e.detail.value.slice(0,300)
				if(temp_value.length>=300){
					this.ask_desc_num = 300
					uni.showToast({
					    icon: 'none',
					    title: '最多只能输入300个字符'
					});
				}else{
					this.ask_desc_num = temp_value.length
				}
				this.ask_desc = temp_value
			},
			handleBlur(e){
				var temp_value = e.detail.value.slice(0,300)
				if(temp_value.length>=300){
					this.ask_desc_num = 300
				}else{
					this.ask_desc_num = temp_value.length
				}
				this.ask_desc = temp_value
			},
		}
	}
</script>

<style lang="scss">
page {
		background-color: #f5f6f8;
	}
	.top_nav_box {
		position: absolute;
		top: 0;
		left: 0;
		z-index: 10;
	}
	.page_item_bj {
		width: 750rpx;
		height:664rpx;
		background-image: url('../../static/images/png03.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 0;
	}
	.page_content_box{
		width: 750rpx;
		position: absolute;
		top: 0;
		left: 0;
		z-index:1;
		.auth_step_img{
			width: 656rpx;
			height: 108rpx;
			margin: 0 auto;
			margin-top: 30rpx;
			margin-bottom:40rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.auth_step_info_box{
			width: 686rpx;
			height: 736rpx;
			background-color: #fff;
			margin: 0 auto;
			border-radius: 12rpx;
			margin-bottom: 20rpx;
			.ask_text_box{
				width: 642rpx;
				height:236rpx;
				background: #F5F6F8;
				border-radius:16rpx;
				margin: 0 auto;
				.ask_textarea{
					width: 600rpx;
					height: 160rpx;
					margin: 0 auto;
					padding-top: 20rpx;
					textarea{
						font-size: 28rpx;
						width: 600rpx;
						height: 160rpx;
					}
				}
				.ask_text_num{
					color: #909399;
					font-size: 24rpx;
					text-align: end;
					padding-right: 30rpx;
				}
			}
			.ask_img_box{
				width: 642rpx;
				margin: 0 auto;
				position: relative;
				.ask_img_num{
					position: absolute;
					top: 28rpx;
					right: 30rpx;
					color: #909399;
					font-size: 24rpx;
				}
				.ask_title{
					padding-top: 28rpx;
					font-size: 30rpx;
					color: rgba(48, 49, 51, 1);
				}
				.img_list{
					display: flex;
					width: 642rpx;
					margin: 0 auto;
					margin-top: 10rpx;
					// flex-wrap: wrap;
				}
			}
			.auth_step_info_title{
				height: 96rpx;
				line-height: 96rpx;
				border-bottom: 2rpx solid rgba(235, 238, 245, 1);
				margin-bottom: 30rpx;
				text{
					color: rgba(48, 49, 51, 1);
					font-size: 32rpx;
					margin-left: 24rpx;
					font-weight: bold;
				}
			}
			.phone_login_input_box{
				width:638rpx;
				height: 88rpx;
				border-radius: 16rpx;
				background: #F5F6F8;
				margin: 0 auto;
				display: flex;
				margin-bottom: 20rpx;
				.pick_box{
					position: relative;
					font-size: 28rpx;
					width: 434rpx;
					height: 88rpx;
					.pick_img{
						width: 56rpx;
						height: 56rpx;
						margin-left:396rpx;
						image{
							width: 44rpx;
							height: 44rpx;
							margin-top:24rpx;
						}
					}
					picker{
						z-index: 9;
						position: absolute;
						top: 0;
						left: 0;
						width: 434rpx;
						height: 88rpx;
						.pick_input{
							height: 88rpx;
							line-height: 88rpx;
							text-align: left;
							font-size: 30rpx;
						}
						.pick_input1{
							font-size: 30rpx;
							color: #808080;
						}
					}
				}
				.phone_login_input_name{
					width: 156rpx;
					height: 88rpx;
					padding-left: 24rpx;
					line-height: 88rpx;
					color: #303133;
					font-size: 30rpx;
					font-weight: bold;
					text{
						color: rgba(255, 77, 79, 1);
					}
				}
				.phone_login_input_inp{
					width: 434rpx;
					height: 88rpx;
					position: relative;
					.reg_form_item_pwd{
						width: 60rpx;
						height: 60rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						position: absolute;
						top: 13rpx;
						right: 12rpx;
						image{
							width: 33rpx;
							height: 33rpx;
						}
					}
					.phone_login_input_code{
						position: absolute;
						top: 13rpx;
						right: 12rpx;
						color: rgba(255, 107, 0, 1);
						font-size: 28rpx;
						z-index: 90;
						width: 190rpx;
						height: 64rpx;
						text-align: center;
						line-height: 64rpx;
						border-radius: 12rpx;
						background-color: rgba(255, 122, 0, 0.1);
					}
					input{
						height: 88rpx;
						line-height: 88rpx;
						font-size: 30rpx;
					}
				}
			}
		}
	}
	.record_fix_box{
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 9;
		width: 750rpx;
		padding-top: 16rpx;
		box-shadow: 0rpx 0rpx 26rpx 0rpx rgba(0,0,0,0.0800);
		padding-bottom: calc(16rpx +  constant(safe-area-inset-bottom));
		padding-bottom: calc(16rpx +  env(safe-area-inset-bottom));
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		.record_fix_btn{
			width: 690rpx;
			height: 80rpx;
			opacity: 1;
			border-radius: 16rpx;
			background:#418aff;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #fff;
			font-size: 30rpx;
		}
	}
</style>
